package com.etool.commons.utils;


import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringEscapeUtils;

import net.sf.json.JSONObject;



public class AjaxUtils {
		
	public static void write(HttpServletResponse response, String content)  {	
		try
		{
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().write(content);
		response.getWriter().flush();
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void writeJson(HttpServletResponse response, Map<String, Object> map) {	
		try {
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().write(JSONObject.fromObject(map).toString());
			response.getWriter().flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void writeJsonEscapeHtml(HttpServletResponse response, Map<String, Object> map) {	
		try {
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().write(StringEscapeUtils.escapeHtml(JSONObject.fromObject(map).toString()));
			response.getWriter().flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
